/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.mes.domain.query;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 *
 *
 * @author zgy
 * @date 2022-2-11
 */
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class ManufactureResultQuery {

    private static final int DEFAULT_PAGE_SIZE = 20;
    private static final int MAX_PAGE_SIZE = 1000;

    /**
     * 返回记录的起始位置。
     */
    private Integer offset;

    /**
     * 返回记录的个数。
     */
    private Integer rows;

    /**
     * 状态：0-已放行
     */
    private Integer status;
    /**
     * 生产任务Id
     */
    private List<Long> manufactureTaskIdList;

    /**
     * 开始时间
     */
    private LocalDateTime createTimeBegin;
    /**
     * 结束时间
     */
    private LocalDateTime createTimeEnd;

    private Boolean withGoodsFlag;

    public Boolean getWithGoodsFlag() {
        return Objects.equals(true, withGoodsFlag);
    }

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     */
    public ManufactureResultQuery(Integer pageIndex) {
        this(pageIndex, DEFAULT_PAGE_SIZE);
    }

    /**
     * 构建一个查询。
     *
     * @param    pageIndex    页索引
     * @param    pageSize    页大小
     */
    public ManufactureResultQuery(Integer pageIndex, Integer pageSize) {
        int index = pageIndex == null ? 0 : pageIndex;
        int size = pageSize == null ? DEFAULT_PAGE_SIZE : pageSize;
        this.offset = index * size;
        this.rows = size;
    }

    /**
     * 构造符合条件的查询对象，仅返回一条
     *
     * @return
     */
    public static ManufactureResultQuery.ManufactureResultQueryBuilder one() {
        return ManufactureResultQuery.builder().offset(0).rows(1);
    }

    /**
     * 构造符合条件的查询对象，控制返回的记录上限
     *
     * @return
     */
    public static ManufactureResultQuery.ManufactureResultQueryBuilder max() {
        return ManufactureResultQuery.builder().offset(0).rows(MAX_PAGE_SIZE);
    }

}
